package com.iss.okair.controller.assetstrans;

import com.iss.common.Message;
import com.iss.common.UuidTools;
import com.iss.okair.db.entity.AssetsPermanent;
import com.iss.okair.db.entity.AssetsTranUse;
import com.iss.okair.db.entity.Assetstrans;
import com.iss.okair.service.trans.PermanentTransService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("logic/trans/permanent")
public class PermanentTransController {

    @Autowired
    private PermanentTransService service;

    @RequestMapping("/checkin/list")
    public List<AssetsTranUse> find(AssetsTranUse model){
        return service.find(model);
    }
    @RequestMapping("/checkout/list")
    public List<AssetsTranUse> findout(AssetsTranUse model){
        return service.findout(model);
    }
    @RequestMapping("/history/{assetsid}")
    public List<AssetsTranUse> checkrecord(@PathVariable String assetsid){
        return service.findrecord(assetsid);
    }
    @RequestMapping("/instock")
    public Message add(Assetstrans trans){
        Message msg = new Message();
        if(service.add(trans)){
            msg.setError(false);
            msg.setMsg("入库成功");
        }
        else{
            msg.setError(true);
            msg.setMsg("入库失败");
        }
        return msg;
    }
    @RequestMapping("/{transtype}")
    public Message Use(@PathVariable("transtype") String transtype, Assetstrans finance){
        Message msg =new Message();
        finance.setId(UuidTools.buildUUID());
        if (service.Use(transtype,finance)){
            msg.setError(false);
            msg.setMsg("成功");
        }else {
            msg.setError(true);
            msg.setMsg("失败");
        }
        return  msg;
    }
}
